﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using DTC.Database;

namespace DTC.Popups
{
    /// <summary>
    /// Interaction logic for OrderingOptions.xaml
    /// </summary>
    public partial class OrderingOptionsPopup : Window
    {
        public OrderingOptionsPopup()
        {
            InitializeComponent();
            this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            MainGrid.DataContext = orderingSettings;
            isNew = true;
        }

        private OrderingSystem orderingSettings;
        public OrderingSystem OrederingSettings
        {
            get
            {
                return orderingSettings;
            }
            set
            {
                if (orderingSettings != value)
                {
                    orderingSettings = value;
                    MainGrid.DataContext = value;
                    isNew = false;
                }
            }
        }
        bool isNew;
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (DialogResult == true)
            {
                if (isNew)
                {
                    App.DBI.Db.OrderingSystems.InsertOnSubmit(orderingSettings);
                }
                App.DBI.Db.SubmitChanges();
            }
        }
    }
}
